<template>
  <div>

    <el-row :gutter="20">
      <el-form :model="searchLsit" ref="searchLsit" size="normal">
        <el-col :span="8" :offset="0">
          <el-form-item label="">
            <el-input v-model="searchLsit.code" clearable placeholder="账号"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" :offset="0">
          <el-form-item label="">
            <el-input v-model="searchLsit.name" clearable placeholder="名称"></el-input>
          </el-form-item>
        </el-col>
      </el-form>
      <el-col :span="8" :offset="0">
        <div class="right">
          <el-button type="primary" size="default" @click="search" :loading="loading">查询</el-button>
          <!-- <el-button type="primary" size="default" @click="onAdd" :loading="loading">添加审核机构</el-button> -->
        </div>
      </el-col>
    </el-row>

    <el-table :data="tebleData" border stripe v-loading="loading" :height="offsetHeight">
      <el-table-column type="index" label="序号" width="80" align="center">
      </el-table-column>
      <el-table-column prop="code" label="单位账号" width="" align="center">
      </el-table-column>
      <el-table-column prop="name" label="单位名称" width="" align="center">
      </el-table-column>
      <el-table-column label="是否开启" width="100" align="center">
        <template slot-scope="{row}">
          <el-tag :type="row.maintain_check_flag ==='0'?'success':'danger'" size="normal">
            {{row.maintain_check_flag =='0'?'开':'关'}}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="100" align="center">
        <template slot-scope="{row}">
          <el-button type="primary" size="mini" @click="edit(row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="机构设置" :visible.sync="show" width="30%" @close="cancel">
      <el-form :model="companyList" ref="companyList" label-width="100px" size="normal">
        <el-form-item label="是否开启">
          <el-select v-model="companyList.maintain_check_flag" value-key="maintain_check_flag" placeholder=""
            class="wid">
            <el-option label="开" value="0">
            </el-option>
            <el-option label="关" value="1">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="机构名称">
          <el-input v-model="companyList.name"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer">
        <el-button type="danger" @click="cancel">取消</el-button>
        <el-button type="primary" @click="onConfirm" :loading="loading">确认</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: 'PartCompany',
  components: {

  },
  props: {

  },
  data () {
    return {
      offsetHeight: document.documentElement.clientHeight - 280,
      loading: false,
      searchLsit: {},
      tebleData: [],
      show: false,
      companyList: {}
    }
  },
  created () {

  },
  mounted () {
    this.init()
  },
  methods: {
    async init () {
      this.loading = true
      const res = await this.$http('sysThirdList', {
        ...this.searchLsit
      })
      this.tebleData = res
      this.loading = false
    },
    search () {
      this.init()
    },
    onAdd () {

    },
    edit (item) {
      this.companyList = {
        id: item.id,
        name: item.name,
        maintain_check_flag: item.maintain_check_flag
      }
      this.show = true
    },
    cancel () {
      this.show = false
    },
    async onConfirm () {
      this.loading = true
      const res = await this.$http('sysThirdUp', {
        id: this.companyList.id,
        name: this.companyList.name,
        maintain_check_flag: this.companyList.maintain_check_flag
      })
      this.$tips.success(res.errmsg)
      this.show = false
      this.init()
    }
  },
  computed: {

  }
}
</script>
<style lang='scss' scoped>
</style>
